﻿<%@ page import="com.cai.dao.UserDao" %>
<%@ page import="com.cai.dao.impl.UserDaoImpl" %>
<%@ page import="com.cai.entity.User" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    UserDao userDao = new UserDaoImpl();
    List<User> userList = userDao.userQueryAll();
    request.setAttribute("userList", userList);
%>
<head>
    <title>会员列表</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="style/adminStyle.css" rel="stylesheet" type="text/css"/>
    <script src="js/jquery.js"></script>
    <script src="js/public.js"></script>
</head>
<body>
<div class="wrap">
    <div class="page-title">
        <span class="modular fl"><i class="user"></i><em>用户列表</em></span>
        <span class="modular fr"><a href="add_user.jsp" class="pt-link-btn">添加新用户</a></span>
    </div>
    <div class="operate">
        <form>
            <select class="inline-select">
                <option hidden disabled selected>选择用户类型</option>
                <option>学生</option>
                <option>教师</option>
            </select>
            <input type="text" class="textBox length-long" placeholder="输入用户昵称、姓名、手机号码..."/>
            <input type="button" value="查询" class="tdBtn"/>
        </form>
    </div>
    <table class="list-style userTable Interlaced">
        <tr>
            <th>序号</th>
            <th>编号</th>
            <th>用户昵称</th>
            <th>用户姓名</th>
            <th>电子邮箱</th>
            <th>手机号码</th>
            <th>用户类型</th>
            <th>操作</th>
        </tr>
        <!--   遍历用户 分页功能-->
        <c:forEach items="${requestScope.pageList_user}" varStatus="status" var="user">
            <tr class="userItem">
                <td class="center">${status.count}</td>
                <td class="center">
                    <label>
                        <input name="user_check" value=${user.user_id} type="checkbox"/>
                    </label>
                    <span class="middle">${user.user_id}</span>
                </td>
                <td class="center user_user">${user.user}</td>
                <td class="center user_name">${user.user_name}</td>
                <td class="center">${user.user_email}</td>
                <td class="center">${user.user_phone}</td>
                <td class="center">${user.user_type}</td>
                <td class="center">
                    <a id="user_update" class="inline-block" title="编辑"><img src="images/icon_edit.gif"/></a>
                    <a class="inline-block" id="user_delete" title="删除"><img src="images/icon_drop.gif"/></a>
                </td>
            </tr>
        </c:forEach>
    </table>
    <!-- BatchOperation -->
    <div style="overflow:hidden;">
        <!-- Operation -->
        <div class="BatchOperation fl">
            <input type="checkbox" id="del"/>
            <label for="del" class="btnStyle middle">全选</label>
            <input type="button" value="批量删除" class="btnStyle"/>
        </div>

        <!-- turn page -->
        <div class="turnPage center fr">
            <label>共${requestScope.totalPage}页&nbsp;&nbsp;共${requestScope.totalCount}行数据</label>
            <label>第</label>
            <c:forEach begin="1" step="1" end="${requestScope.totalPage}" var="count">
                <label><a href="<%=request.getContextPath()%>/pageUser?page=${count}">${count}</a></label>
            </c:forEach>
            <label>页</label>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        //编辑事件
        $("[id=user_update]").click(function () {
            //获取指定名称或者id
            $.ajax({
                url: "/cai/update",
                type: "get",
                data: {
                    user_user: $(this).parent().parent().find(".user_user").text(),
                    user_name: $(this).parent().parent().find(".user_name").text()
                },
                success: function (data) {
                    if (parseInt(data) === 1) {
                        //成功
                        location.href = "add_user.jsp"
                    } else {
                        //失败
                        alert("数据发送失败")
                    }
                }
            })
        })
        //删除事件
        $("[id=user_delete]").click(function () {
            //获取指定名称或者id
            $.ajax({
                url: "/cai/delete",
                type: "post",
                data: {
                    user_user: $(this).parent().parent().find(".user_user").text(),
                },
                success: function (data) {
                    if (parseInt(data) === 1) {
                        //成功
                        alert("删除成功！")
                        $(this).parent().parent().hide()
                    } else {
                        //失败
                        alert("数据发送失败")
                    }
                }
            })
        })
    })

</script>

</body>
</html>